package com.datamation.swadeshi.view;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.datamation.swadeshi.control.Toast;
import com.datamation.swadeshi.control.data.DatabaseHelper;
import com.datamation.swadeshi.control.data.FTranHedDS;
import com.datamation.swadeshi.control.data.ItemLocDS;
import com.datamation.swadeshi.control.data.LoadingCustomDS;
import com.datamation.swadeshi.model.FTranDet;
import com.datamation.swadeshi.model.FTranHed;
import com.datamation.swadeshi.model.ItemLoc;

import android.content.Context;
import android.util.Log;

public class FragmentItemlocstockUpdate {
	Context context;
	ItemLoc Det = null;
	Double Qty,FinalQty,Qoh,RemQty;
	String valfrom,valto;
	Toast  toast;
	
	
	public FragmentItemlocstockUpdate (Context context) 
	{
		this.context = context;
		
	}
	
	public String IS_Update(String ItemCode,String LocCodefrom,String locCodeTo,String LocFrom,String UpdQty,String AddSub) 
	{
	
		ItemLocDS loc = new ItemLocDS(context);
		ItemLoc sav=new ItemLoc();
		valfrom = loc.getAllitemloc(ItemCode,LocCodefrom);
		valto = loc.getAllitemloc(ItemCode,locCodeTo);
		String aaVal = valfrom.toString();
		ArrayList<ItemLoc> itemloclist=new ArrayList<ItemLoc>();
		Log.d("ItemCode:",ItemCode) ;
		Log.d("LocCode:",LocCodefrom) ;
		
		if(AddSub.equals("D"))
		{

			FinalQty = Double.parseDouble(valfrom.toString())-Double.parseDouble(UpdQty);
			RemQty= Double.parseDouble(valto.toString())+Double.parseDouble(UpdQty);
			
			Log.d("finaqtyD",Double.toString(FinalQty) );
		}
		else if (AddSub.equals("A")) 
		{
			FinalQty = Double.parseDouble(valfrom.toString())-Double.parseDouble(UpdQty);
			RemQty= Double.parseDouble(valto.toString())+Double.parseDouble(UpdQty);
			Log.d("finaqtyA",Double.toString(FinalQty) );
			
		}
	
		
		sav.setFITEMLOC_ITEM_CODE(ItemCode.toString());
		sav.setFITEMLOC_LOC_CODE(LocCodefrom.toString()+"-:-"+locCodeTo.toString());
		sav.setFITEMLOC_QOH(FinalQty.toString()+"-:-"+RemQty);
		
		
		itemloclist.add(sav);
		if(loc.AddnewRecord(itemloclist) > 0)
		{
			
			//toast.createToastMessage("Added successfully", context);
		
		}else 
		{
			
		}
	
		return null;
		
	}

}
